//
//  EFAUtySelDevSubUUIDVC.m
//  efairy
//
//  Created by XiangDongMBP on 2017/8/25.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFAUtySelDevSubUUIDVC.h"

@interface EFAUtySelDevSubUUIDVC ()<UIPickerViewDelegate, UIPickerViewDataSource>
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
@end

@implementation EFAUtySelDevSubUUIDVC
#pragma mark - life cycle
- (instancetype)init {
    self = [super init];
    if (self) {
        self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initLogicData];
    [self initNavigationBar];
    [self initSubViews];
}
- (void)initLogicData {
    
}
- (void)initNavigationBar {
    
}

- (void)initSubViews {
    [self.cancelBtn addTarget:self action:@selector(cancelBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.sureBtn addTarget:self action:@selector(sureBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    
    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    NSArray<NSNumber *> * num = @[@(8), @(4), @(254)];
    return [num[component] integerValue];
}
#pragma mark - UIPickerViewDelegate
/*
 //- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
 //    if (self.rptType == EFARptTypeDay || self.rptType == EFARptTypeMonth || self.rptType == EFARptTypeYear) {
 //        if (component == 0) {
 //            NSInteger year = self.startDateComponents.year + row;
 //            return [NSString stringWithFormat:@"%ld", year];
 //        } else if (component == 1) {
 ////            NSInteger year = self.startDateComponents.year + [pickerView selectedRowInComponent:0];
 //            NSInteger month = 1 + row;
 //            return [NSString stringWithFormat:@"%ld", month];
 //        } else if(component == 2) {
 ////            NSInteger year = self.startDateComponents.year + [pickerView selectedRowInComponent:0];
 ////            NSInteger month = 1 + [pickerView selectedRowInComponent:1];
 //            NSInteger day = 1 + row;
 //            return [NSString stringWithFormat:@"%ld", day];
 //        }
 //    } else if (self.rptType == EFARptTypeWeek) {
 //        if (component == 0) {           // 年
 //            NSInteger year = self.startDateComponents.year + row;
 //            return [NSString stringWithFormat:@"%ld", year];
 //        } else if (component == 1) {    // 周
 //            NSInteger year = self.startDateComponents.year + [pickerView selectedRowInComponent:0];
 //            NSInteger week = 1 + row;
 //            NSDate *date = [self.curCalendar dateWithEra:1 year:year month:1 day:1 hour:0 minute:0 second:0 nanosecond:0];
 //            NSDateComponents *com = [[NSDateComponents alloc] init];
 //            com.day = 7 * row;
 //            NSDate *temp = [self.curCalendar dateByAddingComponents:com toDate:date options:NSCalendarMatchStrictly];
 //            NSDate *startOfWeek; NSTimeInterval length;
 //            [self.curCalendar rangeOfUnit:NSCalendarUnitWeekOfYear startDate:&startOfWeek interval:&length forDate:temp];
 //            NSDate *endOfWeek = [startOfWeek dateByAddingTimeInterval:length - 1];
 //            return [NSString stringWithFormat:@"第%ld周(%@-%@)", week, [startOfWeek xd_MM_dd], [endOfWeek xd_MM_dd]];
 //        }
 //    } else if (self.rptType == EFARptTypeQuarter) {
 //        if (component == 0) {
 //            NSInteger year = self.startDateComponents.year + row;
 //            return [NSString stringWithFormat:@"%ld", year];
 //        } else if (component == 1) {
 //            //            NSInteger year = self.startDateComponents.year + [pickerView selectedRowInComponent:0];
 //            NSInteger quarter = 1 + row;
 //            return [NSString stringWithFormat:@"%ld季度", quarter];
 //        }
 //    }
 //    return @"0";
 //}
 */
/*
 //- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
 //    NSString *title = @"";
 //    if (self.rptType == EFARptTypeDay || self.rptType == EFARptTypeMonth || self.rptType == EFARptTypeYear) {
 //        if (component == 0) {
 //            NSInteger year = self.startDateComponents.year + row;
 //            title = [NSString stringWithFormat:@"%ld", year];
 //        } else if (component == 1) {
 //            NSInteger month = 1 + row;
 //            title = [NSString stringWithFormat:@"%ld", month];
 //        } else if(component == 2) {
 //            NSInteger day = 1 + row;
 //            title = [NSString stringWithFormat:@"%ld", day];
 //        }
 //    } else if (self.rptType == EFARptTypeWeek) {
 //        if (component == 0) {           // 年
 //            NSInteger year = self.startDateComponents.year + row;
 //            title = [NSString stringWithFormat:@"%ld", year];
 //        } else if (component == 1) {    // 周
 //            NSInteger year = self.startDateComponents.year + [pickerView selectedRowInComponent:0];
 //            NSInteger week = 1 + row;
 //            NSDate *date = [self.curCalendar dateWithEra:1 year:year month:1 day:1 hour:0 minute:0 second:0 nanosecond:0];
 //            NSDateComponents *com = [[NSDateComponents alloc] init];
 //            com.day = 7 * row;
 //            NSDate *temp = [self.curCalendar dateByAddingComponents:com toDate:date options:NSCalendarMatchStrictly];
 //            NSDate *startOfWeek; NSTimeInterval length;
 //            [self.curCalendar rangeOfUnit:NSCalendarUnitWeekOfYear startDate:&startOfWeek interval:&length forDate:temp];
 //            NSDate *endOfWeek = [startOfWeek dateByAddingTimeInterval:length - 1];
 //            title = [NSString stringWithFormat:@"第%ld周(%@-%@)", week, [startOfWeek xd_MM_dd], [endOfWeek xd_MM_dd]];
 //        }
 //    } else if (self.rptType == EFARptTypeQuarter) {
 //        if (component == 0) {
 //            NSInteger year = self.startDateComponents.year + row;
 //            title = [NSString stringWithFormat:@"%ld", year];
 //        } else if (component == 1) {
 //            NSInteger quarter = 1 + row;
 //            title = [NSString stringWithFormat:@"%ld季度", quarter];
 //        }
 //    }
 //    NSDictionary * dic = @{NSForegroundColorAttributeName: [UIColor blueColor],
 //                           NSFontAttributeName: [UIFont systemFontOfSize:10]};
 //    return [[NSAttributedString alloc] initWithString:title attributes:dic];
 //}
 */

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    UILabel* tView = (UILabel*)view;
    if (!tView){
        tView = [[UILabel alloc] init];
        tView.font = [UIFont systemFontOfSize:14.0];
        tView.textAlignment = NSTextAlignmentCenter;
    }
    NSString *str = [NSString stringWithFormat:@"%ld", (long)(row + 1)];
    tView.text = str;
    return tView;
}

#pragma mark - event response
- (void)cancelBtnTapped:(UIButton *)btn {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)sureBtnTapped:(UIButton *)btn {
    NSInteger index0 = [self.pickerView selectedRowInComponent:0];
    NSInteger index1 = [self.pickerView selectedRowInComponent:1];
    NSInteger index2 = [self.pickerView selectedRowInComponent:2];
    NSString *subUUID = [NSString stringWithFormat:@"%ld-%ld-%ld", (long)(index0 + 1) , (long)(index1 + 1), (long)(index2 + 1)];
    
    [self dismissViewControllerAnimated:YES completion:^{
        if (self.successHandle) {
            self.successHandle(subUUID);
            self.successHandle = nil;
        }
    }];
}

#pragma mark - private methods
#pragma mark - network request
#pragma mark - getters and setters

@end
